package com.gourd.notice.controller;

import com.gourd.notice.mail.service.MailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 供前期测试使用
 * @author gourd
 */
@RestController
@RequestMapping("/mail")
@Api(tags = "mail", description = "邮件控制器")
@Slf4j
public class MailController {
 
    @Autowired
    private MailService mailService;
 
    @PostMapping("/text-send")
    @ApiOperation(value = "发送文本邮件")
    public void sendTextMail() {
        String[] toMails = new String[]{"869570209@qq.com"} ;
        String subject = "smallgourd 邮件";
        String text = "smallgourd 你好";
        mailService.sendTxtMail(toMails,subject,text);
    }
 
    @PostMapping("/html-send")
    @ApiOperation(value = "发送html格式邮件")
    public void sendHtmlMail() {
        String[] toMails = new String[]{"869570209@qq.com"} ;
        String subject = "smallgourd 邮件";
        StringBuilder sb = new StringBuilder();
        sb.append("<html><head></head>");
        sb.append("<body><h1>spring 邮件测试</h1><p>hello!this is spring mail test。</p></body>");
        sb.append("</html>");
        mailService.sendHtmlMail(toMails,subject,sb.toString());
    }
    @PostMapping("/image-send")
    @ApiOperation(value = "发送图片邮件")
    public void sendAttachedImageMail() {
        String[] toMails = new String[]{"869570209@qq.com"} ;
        String subject = "smallgourd 邮件";
        StringBuilder sb = new StringBuilder();
        sb.append("<html><head></head>");
        sb.append("<body><h1>spring 邮件测试</h1><p>hello!this is spring mail test。</p>");
        // cid为固定写法，imageId指定一个标识
        sb.append("<img src=\"cid:imageId\"/></body>");
        sb.append("</html>");
        mailService.sendAttachedImageMail(toMails,subject,sb.toString());
    }
 
    @PostMapping("/file-send")
    @ApiOperation(value = "发送附件邮件")
    public void sendAttendedFileMail() {
        String[] toMails = new String[]{"869570209@qq.com"} ;
        String subject = "smallgourd 邮件";
        StringBuilder sb = new StringBuilder();
        sb.append("<html><head></head>");
        sb.append("<body><h1>spring 邮件测试</h1><p>hello!this is spring mail test。</p></body>");
        sb.append("</html>");
        mailService.sendAttendedFileMail(toMails,subject,sb.toString());
    }
}
